FROM golang:1.17.6-alpine as builder
WORKDIR /usr/src/app
ENV GOPROXY=https://goproxy.cn
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories && \
apk add --no-cache upx  ca-certificates tzdata
COPY ./go.mod ./
#COPY ./go.sum ./
#RUN go mod download
COPY . .
RUN CGO_ENABLED=0 go build -ldflags "-s -w"  -o httpserver &&\
upx --best httpserver -o _upx_server &&\
mv -f _upx_server httpserver

FROM alpine as runner
copy --from=builder /usr/src/app/httpserver /opt/app/
COPY --from=builder /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
CMD ["/opt/app/httpserver"]
